#include <iostream>
#include <fstream>
#include <sstream>

#include <string>
#include <pwd.h>
#include <unistd.h>

#include "user.h"

int main()
{
	UserData data;
	std::string username;
	std::string password;
	bool alreadyExists = data.exists(UserData::getDefaultFilename());

    	std::cout << "-- Application de gestion des dossiers médicaux -- \n";

    	if(!alreadyExists) {
		std::cout << "First connection - Account creation\n";
		std::cout << "Enter your username:\n>";
		getline(std::cin, username);
    	}

	// Get password
	std::cout << "Enter your password:\n>";
	getline(std::cin, password);

	if(!alreadyExists) {
		data.setUsername(username);
		data.setPassword(password);
		data.save(UserData::getDefaultFilename());
	} else {
		data.load(UserData::getDefaultFilename());
		if(password == data.getPassword()) {
			std::cout << "Welcome to your account, " << data.getUsername() << "\n";
		} else {
			std::cout << "Wrong credentials\n";
		}
	}

    return 0;
}
